package com.itheima.tlias.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias.common.result.Result;
import com.itheima.tlias.pojo.entity.Log;
import com.itheima.tlias.mapper.LogMapper;
import com.itheima.tlias.pojo.po.SelectLogPageParam;
import com.itheima.tlias.pojo.vo.PageBean;
import com.itheima.tlias.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;
    @Override
    public Result selectLogByPageParam(SelectLogPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<Log> logs = logMapper.selectLogByPageParam(param);


        PageBean<Log> logPageBean = new PageBean<>();
        logPageBean.setRows(logs);
        logPageBean.setTotal(page.getTotal());
        return Result.success(logPageBean);
    }

    @Override
    public int insertLog(Log log) {
        log.setUpdateTime(LocalDateTime.now());
        log.setCreateTime(LocalDateTime.now());
        return logMapper.insertLog(log);
    }
}
